package lumis.portal.propertybag;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.IndexColumn;

/**
 * Stores a property's default values.
 *
 * @version $Revision: 10825 $ $Date: 2009-08-04 12:36:40 -0300 (Tue, 04 Aug 2009) $
 * @since 5.0.0
 */
@Entity
@Table(name="lum_PBPropertyDefault")
@GenericGenerator(name="portal-guid", strategy="lumis.portal.dao.hibernate.GuidGenerator")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
class PropertyDefault
{
	@Id @GeneratedValue(generator="portal-guid")
	private String id;
	
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@Fetch(FetchMode.SUBSELECT)
	@CollectionOfElements
	@JoinTable(name="lum_PBPropertyDefValue", joinColumns=@JoinColumn(name="propertyDefaultId"))
	@Column(name="value")
	@IndexColumn(name="position", base=0)
	private List<String> values = new ArrayList<String>();

	/**
	 * Returns this entity's identifier.
	 * @return the identifier.
	 * @since 5.0.0
	 */
	String getId()
	{
		return id;
	}

	/**
	 * Returns the values set for this property default.
	 * @return the values, or an empty list if no value is set.
	 * @since 5.0.0
	 */
	List<String> getValues()
	{
		return values;
	}

	/**
	 * Sets the values for this property default. Any existing value will be
	 * overwritten.
	 * @param values the values to set, or an empty list to remove all values set.
	 * @since 5.0.0
	 */
	void setValues(List<String> values)
	{
		this.values.clear();
		this.values.addAll(values);
	}
}
